package org.komarichin.jdo.persistence;

import com.google.appengine.api.datastore.Email;
import com.google.appengine.api.datastore.Text;
import org.komarichin.beans.IComment;

import javax.jdo.annotations.*;
import java.util.Date;


/**
 * <p>
 * &nbsp;
 * </p>
 * User: Michael Komarichin
 * Date: Mar 6, 2010
 * Time: 12:34:55 AM
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Comment implements IComment<String> {
    private static final long serialVersionUID = -3717445621689502920L;


/*    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key id;*/

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
    private String encodedKey;

    @Extension(vendorName = "datanucleus", key = "gae.pk-name", value = "true")
    private String id;


/*    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;*/
    @Persistent
    private Text content;
    @Persistent
    private Email email;
    @Persistent
    private String user;
    @Persistent
    private Date create = new Date();


    @Override
    public String getContent() {
        return content.getValue();
    }

    @Override
    public void setContent(String content) {
        this.content = new Text(content);
    }

    @Override
    public String getEmail() {
        return email.getEmail();
    }

    @Override
    public void setEmail(String email) {
        this.email = new Email(email);
    }

    @Override
    public String getUser() {
        return user;
    }

    @Override
    public void setUser(String user) {
        this.user = user;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    @Override
    public Date getCreate() {
        return create;
    }

    @Override
    public void setCreate(Date create) {
        this.create = create;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Comment comment = (Comment) o;

        return !(content != null ? !content.equals(comment.content) : comment.content != null) && !(email != null ? !email.equals(comment.email) : comment.email != null) && !(id != null ? !id.equals(comment.id) : comment.id != null) && !(user != null ? !user.equals(comment.user) : comment.user != null);

    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (content != null ? content.hashCode() : 0);
        result = 31 * result + (email != null ? email.hashCode() : 0);
        result = 31 * result + (user != null ? user.hashCode() : 0);
        return result;
    }
}
